//
//  HJNewFriendsCell.m
//  project
//
//  Created by jc on 2019/4/17.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJNewFriendsCell.h"
#import "HJNewFriendsVC.h"

@interface HJNewFriendsCell ()
@property (weak, nonatomic) IBOutlet UIButton *acceptBtn;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UIView *headSubView;
@property (weak, nonatomic) IBOutlet UIImageView *headImage;
@property (nonatomic,strong) HJNewFriendModel * model;
@end
@implementation HJNewFriendsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    // Initialization code
    self.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
}

-(void)loadDataModel:(HJNewFriendModel *)model {
    self.model = model;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:model.user.avatar]];
    self.name.text = model.user.nickName;
    self.acceptBtn.selected = model.status.boolValue;
    if (model.status.boolValue) {
        self.acceptBtn.userInteractionEnabled = NO;
        self.acceptBtn.backgroundColor = [UIColor clearColor];
    }else {
        self.acceptBtn.userInteractionEnabled = YES;
        [self.acceptBtn setHorizontalGradinet:@[[UIColor colorWithHex:0xfe6a7f],[UIColor colorWithHex:0xff8980]]];
        self.acceptBtn.layer.cornerRadius = 15;
        self.acceptBtn.layer.masksToBounds = YES;
    }
}

- (IBAction)acceptBtnClicked:(UIButton *)sender {
    NSString * url= [Api stringByAppendingString:NewFriendAddApi];
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    params[@"noticeId"] = self.model.noticeId;
    params[@"userId"] = [HJUserManager getUserModel].userId;
    WS(weakSelf)
    [HJHttpTool post:url params:params success:^(HJResponeds *result) {
        [[UIViewController currentViewController] showSuccessHUDWithStr:@"添加成功"];
        dispatch_async(dispatch_get_main_queue(), ^{
            [mNotificationCenter postNotificationName:@"agreeNewFriendNotification" object:nil];
            weakSelf.acceptBtn.selected = YES;
            weakSelf.acceptBtn.userInteractionEnabled = NO;
            weakSelf.acceptBtn.backgroundColor = [UIColor clearColor];
        });
    } failure:^(id result) {
        [[UIViewController currentViewController] showErrorHUDWithError:result];
    }];
    
}

@end
